package com.mdl.springmvc.ioStream.io;

import java.io.*;

/**
 * @Desc
 * @Author madengling
 * @Time 2020/12/29 16:35
 */
public class InputStreamReaderTest07 {
    private static final String PATH = "G:\\dhcc\\idea\\MavenProject\\src\\main\\webapp\\files\\d\\";
    public static void main(String[] args) {
        // 定义文件路径,文件为gbk编码
        String FileName = PATH+"A.txt";
        // 创建流对象,默认UTF8编码
        BufferedReader bf = null;
        try {
            bf = new BufferedReader(new InputStreamReader(new FileInputStream(FileName)));
            // 创建流对象,指定GBK编码
            bf = new BufferedReader(new InputStreamReader(new FileInputStream(FileName) , "GBK"));
            // 定义变量,保存字符
            int read;
            // 使用默认编码字符流读取,乱码
            while ((read = bf.read()) != -1) {
                System.out.print((char)read); // ���Ĳ���
            }
            System.out.println();
            // 使用指定编码字符流读取,正常解析
            while ((read = bf.read()) != -1) {
                System.out.print((char)read);// 中文测试
            }
            System.out.println();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                bf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
